{extend name="base/layer_layout" /}

{block name="body"}
<article class="cl pd-20">
    <form action="{:url('admin/AuthManager/access')}" method="post" class="form form-horizontal" id="form-admin-role-add">
        <input type="hidden" name="groupid" value="{$info.id}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理组名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$info.title}" disabled placeholder="" id="" name="">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">方法节点：</label>
            <div class="formControls col-xs-8 col-sm-9">
                {volist name="mainMenuList" id="mainlist"}
                <dl class="permission-list">
                    <dt>
                        <label>
                            <input type="checkbox" value="{$mainlist.url}" name="rule[{$mainlist.id}][name]" id="{$mainlist.id}" <?php if(in_array($mainlist['url'], $rules)){ echo 'checked';}?> >
                            {$mainlist.title}</label>
                        <input type="hidden" name="rule[{$mainlist.id}][type]" value="{$mainlist.menu_type}">
                    </dt>
                    <dd>
                        {volist name="sidebarMenuList[$mainlist['id']]" id="sidebarlist"}
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" value="{$sidebarlist.url}" name="rule[{$sidebarlist.id}][name]" id="{$sidebarlist.id}" <?php if(in_array($sidebarlist['url'], $rules)){ echo 'checked';}?> >
                                    {$sidebarlist.title}</label>
                                <input type="hidden" name="rule[{$sidebarlist.id}][type]" value="{$sidebarlist.menu_type}">
                            </dt>
                            <dd>
                                {notempty name="sidebarlist._child"}
                                    {volist name="sidebarlist._child" id="sidebarlist_child"}
                                        <dl class="cl permission-list2">
                                            <dt>
                                                <label class="">
                                                    <input type="checkbox" value="{$sidebarlist_child.url}" name="rule[{$sidebarlist_child.id}][name]" id="{$sidebarlist_child.id}"  <?php if(in_array($sidebarlist_child['url'], $rules)){ echo 'checked';}?> >
                                                    {$sidebarlist_child.title}</label>
                                                <input type="hidden" name="rule[{$sidebarlist_child.id}][type]" value="{$sidebarlist_child.menu_type}">
                                            </dt>
                                            <dd>
                                                {volist name="buttonMenuList" id="button"}
                                                {eq name="button.pid" value="$sidebarlist_child.id"}
                                                <label class="">
                                                    <input type="checkbox" value="{$button.url}" name="rule[{$button.id}][name]" id="{$button.id}" <?php if(in_array($button['url'], $rules)){ echo 'checked';}?> >
                                                    {$button.title}</label>
                                                    <input type="hidden" name="rule[{$button.id}][type]" value="{$button.menu_type}">
                                                {/eq}
                                                {/volist}
                                            </dd>
                                        </dl>
                                    {/volist}
                                {else}
                                    {volist name="buttonMenuList" id="button"}
                                        {eq name="button.pid" value="$sidebarlist.id"}
                                        <label class="">
                                            <input type="checkbox" value="{$button.url}" name="rule[{$button.id}][name]" id="{$button.id}" <?php if(in_array($button['url'], $rules)){ echo 'checked';}?> >
                                            {$button.title}</label>
                                            <input type="hidden" name="rule[{$button.id}][type]" value="{$button.menu_type}">
                                        {/eq}
                                    {/volist}
                                {/notempty}
                                <!--<label class="c-orange"><input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-5"> 只能操作自己发布的</label>-->
                            </dd>
                        </dl>
                        {/volist}
                    </dd>
                </dl>
                {/volist}
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
            </div>
        </div>
    </form>
</article>
{/block}

{block name="script"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__EXP_PLUGIN__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__EXP_PLUGIN__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__EXP_PLUGIN__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        $(".permission-list dt input:checkbox").click(function(){
            $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        });
        $(".permission-list2 dd input:checkbox").click(function(){
            var l =$(this).parent().parent().find("input:checked").length;
            var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
            if($(this).prop("checked")){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
            }
            else{
                if(l==0){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                }
                if(l2==0){
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                }
            }
        });

        $("#form-admin-role-add").validate({
            rules:{
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit(function (result) {
                    layer.msg(result.msg);
                    if (result.code == 1) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                });

            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}